********************************************************************************************
**** ENGEL CURVES ESTIMATION
**** This file generates output tables for group comparison at baseline.
**** Version: 03/07/2014
********************************************************************************************

* Generate variables

		gen ln_expenditure2 = ln_expenditure * ln_expenditure
		label var ln_expenditure2 "Log Monthly expenditure (squared)" 
		
		gen sh_food2 = sh_food * sh_food
		label var sh_food2 "Food (squared)"
		
		
		gen ln_food = ln(exp_food)
		label var ln_food "Log Food exp."
		
		gen ln_food2 = ln_food * ln_food
		label var ln_food2 "Log Food exp. (squared)" 
		

* Run estimation

		foreach var of varlist $Expenditure_shares_var	{

				reg `var' mother ln_expenditure $controls if round == 2012, cluster(id_mun)
				est sto a 
				
				reg `var' mother ln_expenditure ln_expenditure2 $controls if round == 2012, cluster(id_mun)
				est sto b
				
				reg `var' mother ln_expenditure $controls if round == 2012 & `var' > 0 , cluster(id_mun)
				est sto c 
				
				reg `var' mother ln_expenditure ln_expenditure2 $controls if round == 2012 & `var' > 0, cluster(id_mun)
				est sto d
												
				esttab * using "Outputs/Engel curve_`var'.tex", replace compress f nonumb nomtitles width(1\textwidth) keep(mother ln_expenditure ln_expenditure2) ///
				mgroups("\multicolumn{2}{c}{\textit{All}} & \multicolumn{2}{c}{\textit{Only positive shares}}", span) ///
				collabels("(1)" "(2)" "(3)" "(4)") ///
				label starlevels(* 0.10 ** 0.05 *** 0.01) b(3) r2 se(3) unstack nonote				
				est clear
				
			}

* Run estimation for food items

		foreach var of varlist $Expenditure_shares_food_b	{

				reg s`var' mother ln_food $controls if round == 2012, cluster(id_mun)
				est sto a 
				
				reg s`var' mother ln_food ln_food2 $controls if round == 2012, cluster(id_mun)
				est sto b
				
				reg s`var' mother ln_food $controls if round == 2012 & `var' > 0 , cluster(id_mun)
				est sto c 
				
				reg s`var' mother ln_food ln_food2 $controls if round == 2012 & `var' > 0, cluster(id_mun)
				est sto d
												
				esttab * using "Outputs/Engel curve_`var'.tex", replace compress f nonumb nomtitles width(1\textwidth) keep(mother ln_food ln_food2) ///
				mgroups("\multicolumn{2}{c}{\textit{All}} & \multicolumn{2}{c}{\textit{Only positive shares}}", span) ///
				collabels("(1)" "(2)" "(3)" "(4)") ///
				label starlevels(* 0.10 ** 0.05 *** 0.01) b(3) r2 se(3) unstack nonote				
				est clear
				
			}


* Graphics

		foreach var of varlist $Expenditure_shares_var {
		
			local lab: variable label `var'

			twoway (scatter `var' ln_expenditure if round == 2012 & `var'>0) (lfit `var' ln_expenditure if round == 2012 & `var'>0) (qfit `var' ln_expenditure if round == 2012 & `var'>0), ytitle("Budget share") ti(`lab')  scheme(burd)
			graph export "Graphics/Engel curve_`var'.tif", replace
			
		}
